define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'auctiongood/index' + location.search,
                    // add_url: 'auctiongood/add',
                    // edit_url: 'auctiongood/edit',
                    // del_url: 'auctiongood/del',
                    multi_url: 'auctiongood/multi',
                    table: 'auction_good',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'createtime',
                sortOrder:'desc',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'name', title: __('Name')},
                        {field: 'desc', title: __('Desc'), operate:false},
                        {field: 'images', title: __('Images'), operate:false, events: Table.api.events.image, formatter: Table.api.formatter.images},
                        {field: 'user.nickname', title: __('Publisheruserid'), operate:false},
                        {field: 'users.nickname', title: __('Receiveruserid'), operate:false},
                        {field: 'money', title: __('Money'), operate:false},
                        {field: 'range', title: __('Range'),  operate:false},
                        {field: 'price', title: __('Price'),  operate:false},
                        {field: 'hour', title: __('Hour'), operate:false},
                        {field: 'contacts', title: __('Contacts')},
                        {field: 'telephone', title: __('Telephone')},
                        {field: 'status', title: __('Status'), searchList: {"1":__('Status 1'),"2":__('Status 2'),"3":__('Status 3')}, formatter: Table.api.formatter.status},
                        {field: 'send', title: __('Send'), searchList: {"0":__('Send 0'),"1":__('Send 1'),"2":__('Send 2')}, formatter: Table.api.formatter.status},
                        {field: 'refund', title: __('Refund'), searchList: {"0":__('Refund 0'),"1":__('Refund 1')}, formatter: Table.api.formatter.status},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'browse', title: __('Browse'),operate:false},
                        {field: 'number', title: __('Number'), operate:false},
                        {field: 'auctioncategory.name', title: __('分类'), operate:false},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
                            buttons: [

                                {
                                    name: 'addtabs',
                                    text: __('赏金明细'),
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    icon: 'fa fa-list',
                                    url: 'income/moneyrewardgood'
                                },
                                {
                                    name: 'addtabs',
                                    text: __('聊天记录'),
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    icon: 'fa fa-list',
                                    url: 'chatlog/good'
                                },
                                {
                                    name: 'addtabs',
                                    text: __('竞拍记录'),
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    icon: 'fa fa-list',
                                    url: 'auctionorder/index'
                                },
                                {
                                    name: 'ajax',
                                    text: __('退款'),
                                    classname: 'btn btn-xs btn-success btn-magic btn-ajax',
                                    icon: 'fa fa-magic',
                                    url: 'auctiongood/drawback',
                                    success: function (data, ret) {
                                        Layer.alert(ret.msg);
                                        $('.btn-refresh').trigger('click');
                                        //如果需要阻止成功提示，则必须使用return false;
                                        //return false;
                                    },
                                    error: function (data, ret) {
                                        Layer.alert(ret.msg);
                                        return false;
                                    },
                                    visible: function (row) {
                                        if(row.refund==0&&row.status==3){
                                            return true;
                                        }else{
                                            return false;
                                        }


                                    },
                                }



                            ],
                            formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },

        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});